package com.baidu.booklib.controller;

import com.baidu.booklib.domain.Book;
import com.baidu.booklib.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/book")
//  http://127.0.0.1/book
public class BookController {
    @Autowired
    private BookService bookService;

    @GetMapping("/{id}")
//    http://127.0.0.1/book/id
    public Book selectById(@PathVariable Integer id){
        return bookService.selectById(id);
    }

    @GetMapping("/selectAll")
//    写了一个接口的路径
    public List<Book> selectAll(){
        return bookService.selectAll();
    }

    @PostMapping("/insert")
    public boolean insert(Book book){
        System.out.println("Book对象"+book);
        book.setName(book.getName());
        book.setType(book.getType());
        book.setDescription(book.getDescription());

        return bookService.insert(book);
    }
}
